package com.mxt.alert.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mxt.alert.entity.Despose;
import com.mxt.alert.mapper.DesposeMapper;
import com.mxt.common.vo.Result;
import com.mxt.record.entity.Cord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author mxt
 * @since 2023-06-09
 */
@RestController
@CrossOrigin
@RequestMapping("/example/alert")
public class DesposeController {

    @Autowired
    private DesposeMapper desposeMapper;

    @GetMapping
    public Result listDepose(){
        List<Despose> list = desposeMapper.selectList(null);
        System.out.println(list);
        return Result.success(list);
    }

    @GetMapping("/search/{id}")
    public Result searchById(@PathVariable Integer id){
        Despose despose = desposeMapper.selectById(id);
        return Result.success(despose);
    }
    @PostMapping("/add")
    public Result addDepose(@RequestBody Despose despose){
        desposeMapper.insert(despose);
        return Result.success();
    }

    @DeleteMapping("/delete/{deviceId}")
    public Result deleteDesposeById(@PathVariable Integer deviceId){
        desposeMapper.deleteById(deviceId);
        return Result.success();
    }

    @DeleteMapping("/deleteIds")
    public Result deleteDesposeIds(@RequestBody List deletedIds){
        System.out.println(deletedIds);
        desposeMapper.deleteBatchIds(deletedIds);
        return Result.success();
    }


    @PostMapping("/update")
    public Result updateDeposeById(@RequestBody Despose despose){
        Integer id = despose.getId();
        System.out.println(id);
        desposeMapper.updateById(despose);
        return Result.success();
    }
    @GetMapping("/page")
    public Result getPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){

        Page<Despose> page = new Page<>(pageNum,pageSize);
        Page<Despose> desposePage = desposeMapper.selectPage(page, null);
        List<Despose> list = desposePage.getRecords();
        System.out.println(desposePage.getTotal());
        return Result.success(list);
    }




}
